/*This activity contains the chat fragment. 
 * The layout is in the chat.xml file.
 * This file describe what happens when you select an item from the ContactListFragment. */
package dk.aau.walkietalkieui;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import dk.aau.walkietalkieui.fragment.ChatFragment;

public class ChatActivity extends Base_FragmentActivity {

	public final static String KEY_SELECTED_INDEX = "selIndex";
	public final String TAG = "ChatActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chat);

		if (savedInstanceState == null) {
			Bundle extras = getIntent().getExtras();

			if (extras != null && extras.containsKey(KEY_SELECTED_INDEX)) {
				int selIndex = extras.getInt(KEY_SELECTED_INDEX);

				FragmentManager fm = getSupportFragmentManager();

				FragmentTransaction ft = fm.beginTransaction();
				ft.replace(R.id.ChatFragmentContent,
						ChatFragment.newInstance(selIndex), ChatFragment.TAG);
			
				ft.commit();
			} else {
				Log.e(TAG, "No selected index supplied!");
				finish();
			}
		}
	}

}
